package fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a513.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link FragmentDynamic#newInstance} factory method to
 * create an instance of this fragment.
 */
public class FragmentDynamic extends Fragment {



    public FragmentDynamic() {
        // Required empty public constructor
    }


    public static FragmentDynamic newInstance(int position,int img_id, String desc) {
        FragmentDynamic fragment = new FragmentDynamic();
        Bundle args = new Bundle();
        args.putInt("position", position);
        args.putInt("img_id", img_id);
        args.putString("desc",desc);
        fragment.setArguments(args);
        return fragment;
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_dynamic, container, false);
        Bundle arguments = getArguments();
        if (arguments != null){
            TextView tv_desc = view.findViewById(R.id.tv_desc);
            ImageView iv_pic = view.findViewById(R.id.iv_pic);
            iv_pic.setImageResource(arguments.getInt("img_id"));
            tv_desc.setText(arguments.getString("desc"));
        }
        return view;
    }
}